<?php
header("Content-Type: text/html; charset=utf-8"); 

require_once("config.inc.php");
require_once(COMM_PATH."book.php");
function strlen_utf8($str) {
	$i = 0;
	$count = 0;
	$len = strlen ($str);
	while ($i < $len) {
		$chr = ord ($str[$i]);
		$count++;
		$i++;
		if($i >= $len) break;
		if($chr & 0x80) {
			$chr <<= 1;
			while ($chr & 0x80) {
				$i++;
				$chr <<= 1;
			}
		}
	}
	return $count;
}
//utf-8 中文字符截取
function utf8Substr($str, $from, $len)
{
    return preg_replace('#^(?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,'.$from.'}'.
                       '((?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,'.$len.'}).*#s',
                       '$1',$str);
}

$book = new Book();

if ($_GET['BID']){
	$BOOKID = $_GET['BID'];
	$The_book = $book->getBook($BOOKID);
	$categroy = $book->getInfo($The_book[0]['category'], $book->_CATEGORY);
	$CP = $The_book[0]['bookName'];
}else{
	require('404.php');
    @header('HTTP/1.1 404 Not Found');
    @header('Status: 404 Not Found');
    exit;
}
 
$desc = ",".$categroy[0]['cate_name'].",".$The_book[0]["bookName"];
?>
<?php include_once 'top.php';?>

<div class="b_lofter bgWhite">
	<div class="breadcrumb">
		您的位置：<a href="/"  title="木篱笆书站">首页</a>&nbsp;/&nbsp;<a href="/?CP=<?php echo $The_book[0]['category'];?>"><?php echo $categroy[0]['cate_name'];?></a>&nbsp;/&nbsp;<?php echo $The_book[0]["bookName"];?>
	</div>
	<div class="brline">
	</div>
	<div class="book_list">
    	<div class="book_content  fn-clear">
        	<div class="book_img"><img src="<?php echo INCLUDE_WEB."IMAGE_FILE/min/".$The_book[0]["imagePath"];?>"  alt="<?php echo $The_book[0]["bookName"];?>"/></div>
            <div class="book_intr">
            	<h2><?php echo $The_book[0]["bookName"];?></h2>
                <p>作者：<?php echo $The_book[0]["author"];?>
						
						 <br />
                	<?php if ($The_book[0]["intro"]){
                	
                		echo "简介：".$The_book[0]["intro"];
                	}?>
                 </p>
				  
            </div>
        </div>
        <div class="book_menu_list">
        	<ul class="fn-clear">
        	<?php 
        	$filepath = INCLUDE_PATH.$The_book[0]["path"]."/0.txt";
			$content = "";
			if (file_exists($filepath)){
				$content = file_get_contents($filepath);
			}else {
				echo "<script type=\"text/javascript\">window.location.href=\"404.php\";</script>";
				exit;
			}
			$array = explode("\r\n", $content);
			$chNum = count($array);
			for($i=0; $i<$chNum; $i++)
			{
				$readId = $i+1;
				$titleNum = strlen_utf8($array[$i]);
				if($titleNum>20){
					$showtilte = utf8Substr($array[$i], 0,20)."...";
				}else{
					$showtilte = $array[$i];
				}
			    echo "<li><a href=\"Read.php?BID=$BOOKID&CH=$readId&CHN=$chNum\" title=\"$array[$i]\">$showtilte</a></li>";
			}
        	?>
            </ul>
        </div>
		<div class="book_share">
				<!-- JiaThis Button BEGIN -->
				<div id="jiathis_style_32x32">
				<a class="jiathis_button_tsina"></a>
				<a class="jiathis_button_qzone"></a>
				<a class="jiathis_button_renren"></a>
				<a class="jiathis_button_tqq"></a>
				<a class="jiathis_button_douban"></a>
				<a class="jiathis_button_googleplus"></a>
				<a class="jiathis_button_t163"></a>
				<a href="http://www.jiathis.com/share?uid=1609438" class="jiathis jiathis_txt jiathis_separator jtico jtico_jiathis" target="_blank"></a>
				<a class="jiathis_counter_style"></a>
				</div>
				<script type="text/javascript" >
				var jiathis_config={
					data_track_clickback:true,
					summary:"",
					hideMore:false
				}
				</script>
				<script type="text/javascript" src="http://v2.jiathis.com/code/jia.js?uid=1609438" charset="utf-8"></script>
				<!-- JiaThis Button END -->
		</div>
    </div>
</div>


<?php include_once 'footer.php';?>
